/**
 * Created by CZ on 2017/4/6.
 */
module.exports = function ($scope,RequestService,$rootScope,commonConfig) {
    $rootScope.DeveloperHeaderShow = true; //显示头部
    $rootScope.DeveloperFooterShow = true; //显示尾部
    $rootScope.DeveloperNavShow = true;  //显示nav

    getWikiList();
    $scope.oneAtATime = false;
    $scope.status = {
        isFirstOpen: true,
        isFirstDisabled: true,
        open:true,
        disabled:true
    };
    //获取详情
    $scope.getWikiDetail = function(id){
        console.log(id);
        angular.forEach($scope.WikiList,function(val,i){   //更改样式
            if(val.id == id){
                val.open = true;
            }else {
                val.open = false;
            }
        });
        RequestService.Request(commonConfig.cloudApi+'wiki/'+id,'GET').then(function(response){
            // console.log(response);
            $scope.content = response.remark;
            // $scope.content = $sce.trustAsHtml($scope.content);
        },function(error){
            console.log(error);
        })
    };

    function getWikiList(){
        RequestService.Request(commonConfig.cloudApi+'wiki','GET').then(function(response){
            // console.log(response);
            $scope.WikiList = response;
            angular.forEach($scope.WikiList,function(val,i){  //添加打开属性
                //console.log(val,i);
                if(val.parentId != 0){
                    val.open = false;
                }
            });
            //获取第一个父级标签id
            var id = 0;
            for (var i=0;i<$scope.WikiList.length;i++){
                if($scope.WikiList[i].parentId == 0){
                    id = $scope.WikiList[i].id;
                    break;
                }
            }
            //获取第一个信息
            for (var j=0;j<$scope.WikiList.length;j++){
                if($scope.WikiList[j].parentId == id ){
                    $scope.getWikiDetail($scope.WikiList[j].id);
                    break;
                }
            }
            console.log($scope.WikiList);
        },function(error){
            console.log(error);
        });

    }
    
};